﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using OgilvyOne.Model;
using OgilvyOne.DALFactory;
using OgilvyOne.Utility;
using System.Runtime.Remoting.Contexts;
using System.Configuration;
using System.Web;


namespace OgilvyOne.BLL
{
    /// <summary>
    /// 前台栏目(菜单)解析类

    /// </summary>
    public class MenuModel
    {

        public static string DEBUG = System.Configuration.ConfigurationSettings.AppSettings["Debug"];

        //private const int CN_HOME_ID = ConConstants.HOME_ID;
        private int cid; //当前ID
        private int aid; //当前内容
        private static IList columnlist; //所有栏目

        private static Hashtable columnmap; //栏目map
        private string rootDir;
        public static readonly int CnHomeColumnID = 455;
        public static readonly int EnHomeColumnID = 482;

        public MenuModel()
        {
            cid = GetHomeId();
            init();
        }
        public MenuModel(int cid, int aid)
        {
            this.cid = cid;
            this.aid = aid;
            init();
        }
        public MenuModel(int cid)
        {
            this.cid = cid;
            init();
        }

        protected virtual int GetHomeId()
        {
            return ConConstants.HOME_ID;
        }
        /// <summary>
        /// 根目录
        /// </summary>
        /// <returns></returns>
        protected string GetRootDir()
        {
            return "/" + rootDir;
        }

        public void SetCid(int cid)
        {
            this.cid = cid;
        }
        /// <summary>
        /// 栏目主菜单ID
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public int GetMainColumnId(int cid)
        {
            string layerid = GetColumn(cid).Layerid;
            string[] ls = layerid.Split(',');
            return int.Parse(ls[2]);
        }
        /// <summary>
        /// 当前栏目主菜单ID
        /// </summary>
        /// <returns></returns>
        public int GetMainColumnId()
        {
            return GetMainColumnId(cid);
        }


        public void SetAid(int aid)
        {
            this.aid = aid;
        }
        //初始栏目数据
        private void init()
        {
            bool isupdate = ColumnBll.IsUpdate();
            if (columnlist == null || isupdate)
            {
                columnlist = ColumnBll.GetColumnList();
            }
            if (columnmap == null || isupdate)
            {
                columnmap = new Hashtable();
                for (int i = 0; i < columnlist.Count; i++)
                {
                    ColumnModel cm = (ColumnModel)columnlist[i];
                    columnmap.Add(cm.Classid, cm);
                }
            }
            rootDir = GetColumn(GetHomeId()).Eclassname;
        }

        public bool IsDebug()
        {
            if (DEBUG != null && DEBUG == "1")
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 返回当前栏目信息
        /// </summary>
        /// <returns></returns>
        public ColumnModel GetColumn()
        {
            return GetColumn(cid);
        }
        /// <summary>
        /// 返回栏目信息
        /// </summary>
        /// <param name="_cid"></param>
        /// <returns></returns>
        public ColumnModel GetColumn(int _cid)
        {
            return (ColumnModel)columnmap[_cid];
        }
        /// <summary>
        /// 获取子栏目
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public IList GetSonColumn(int pid)
        {
            IList datalist = new ArrayList();
            for (int i = 0; i < columnlist.Count; i++)
            {
                ColumnModel cm = (ColumnModel)columnlist[i];
                if (cm.Parentid == pid)
                {
                    datalist.Add(cm);
                }
            }
            return datalist;
        }
        /// <summary>
        /// 获取导航子栏目
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public IList GetNavSonColumn(int pid)
        {
            IList datalist = new ArrayList();
            for (int i = 0; i < columnlist.Count; i++)
            {
                ColumnModel cm = (ColumnModel)columnlist[i];
                if (cm.Parentid == pid && cm.Isshow == 1) //并且导航
                {
                    datalist.Add(cm);
                }
            }
            return datalist;
        }

        /// <summary>
        /// 获取层级所有子栏目
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public IList GetLayeridColumn(int pid)
        {
            IList datalist = new ArrayList();
            ColumnModel pcm = GetColumn(pid);
            string layerid = pcm.Layerid;
            for (int i = 0; i < columnlist.Count; i++)
            {
                ColumnModel cm = (ColumnModel)columnlist[i];
                if (cm.Classid != pid && cm.Layerid.IndexOf(layerid) > -1)
                {
                    datalist.Add(cm);
                }
            }
            return datalist;
        }

        public string GetLayerDir(string layerid)
        {
            string dir = "";
            string[] cs = layerid.Split(',');
            foreach (string _cid in cs)
            {
                int _cidi = int.Parse(_cid);
                if (_cidi >= GetHomeId())
                {
                    ColumnModel cm = GetColumn(_cidi);
                    if (cm!=null && cm.Eclassname != null && cm.Eclassname.Trim() != "")
                    {
                        dir += "/" + cm.Eclassname;
                    }
                }
            }
            return dir;
        }

        /// <summary>
        /// 栏目Url
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public string GetUrl(int cid)
        {
            return GetUrl(GetColumn(cid));
        }
        public string GetUrl(ColumnModel cm)
        {
            if (cm.Templateindex == 0 && !(cm.Columnfilename != null && cm.Columnfilename != ""))
            {
                return "javascript:;";
            }
            else if (cm.Columnfilename != null && cm.Columnfilename != "")
            {
                if (IsDebug() == false || cm.Columnfilename.IndexOf(".aspx") > 0)
                {
                    if (cm.Columnfilename.IndexOf("http://") > -1)
                    {
                        return "javascript:openADUrl('" + cm.Columnfilename + "','c-"+ cm.Classid +"');void(0);";
                    }
                    if (cm.Columnfilename.IndexOf("/") > -1)
                    {
                        return cm.Columnfilename;
                    }
                    string dir = GetLayerDir(cm.Layerid);
                    return dir + "/" + cm.Columnfilename;
                }
            }
            else if (cm.Class_is_static == CmsConstants.YES)
            {
                if (IsDebug() == false)
                {
                    string dir = GetLayerDir(cm.Layerid);
                    return dir + "/" + GetColumnHtmlFileName(cm);
                }
            }
            return GetRootDir() + "/content.aspx?cid=" + cm.Classid;
        }
        public static string GetColumnHtmlFileName(ColumnModel cm)
        {
            return cm.Columnfilename != null && cm.Columnfilename != "" ? cm.Columnfilename : "c-" + cm.Classid + ".html" ;
        }
        public static string GetAritcleHtmlFileName(CmsArticleModel cm)
        {
            return cm.Staticpagename != null && cm.Staticpagename.Trim() != "" ? cm.Staticpagename : cm.Articleid + ".html" ;
        }
        public string GetPageUrl(int cid, int pagenum)
        {
            return GetRootDir() + "/content.aspx?cid=" + cid + "&pagenum=" + pagenum;
        }
        /// <summary>
        /// 文章URL
        /// </summary>
        /// <param name="cm"></param>
        /// <returns></returns>
        public string GetArticleUrl(CmsArticleModel cm)
        {

            if (cm.Articletype == OgilvyOne.Utility.CmsConstants.ARTICLE_TYPE_DOWNLOAD)
            {
                return ConConstants.UPLOADFILES_FILE_PATH + cm.Linkpath;
            }
            else if (cm.Articletype == OgilvyOne.Utility.CmsConstants.ARTICLE_TYPE_LINK)
            {
                return cm.Linkpath; //"javascript:window.open('"+ cm.Linkpath + "','_blank');"
            }
            if (cm.Isstaticpub == CmsConstants.YES.ToString())
            {
                if (IsDebug() == false)
                {
                    string dir = GetLayerDir(GetColumn(cm.Columnid).Layerid);
                    return dir + "/" + GetAritcleHtmlFileName(cm);
                }
            }
            return GetRootDir() + "/content.aspx?aid=" + cm.Articleid;
        }

        /// <summary>
        /// 获得品牌链接
        /// </summary>
        /// <param name="bid"></param>
        /// <returns></returns>
        public string GetBrandUrl(int bid)
        {

            return GetRootDir() + "/brand/products.aspx?id=" + bid;
        }

        //public string GetFileDownloadUrl(CmsArticleModel cm);

        public string GetLeftNavi(int rootColumnID)
        {
            string[] colors = { "violet", "blue" };

            ColumnModel _dcm = GetColumn(); //当前
            int columnIndex = FindColumnIndex(rootColumnID, _dcm.Layerid);

            ColumnModel rootColumn = GetColumn(rootColumnID);
            string rootFolder = rootColumn.Eclassname;
            string arrowImg = string.Format("/{0}/images/leftbar_nav_arrow_gray.gif", rootFolder);
            string color = colors[columnIndex % 2];

            ColumnModel firstLevelColumn = FindColumnByIndex(rootColumnID, columnIndex);
            if (firstLevelColumn == null) return null;

            IList childColumns = GetNavSonColumn(firstLevelColumn.Classid);
            if (childColumns.Count == 0)
                color = colors[0];

            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("<div class=\"{0}\">", color);
            builder.Append("    <ul>");

            int i = 1;
            if (childColumns.Count == 0)
            {
                string selectedImg = string.Format("/{0}/images/leftbar_nav_{1}_1_now.gif", rootFolder, columnIndex);
                string url = string.Format("/{0}/{1}", rootFolder, firstLevelColumn.Columnfilename);
                builder.AppendFormat("<li><a href=\"{0}\"><img src=\"{1}\" alt=\"\" /></a></li>", url, selectedImg);
            }
            else
            {
                foreach (ColumnModel childColumn in childColumns)
                {
                    string selectedImg = string.Format("/{2}/images/leftbar_nav_{0}_{1}_now.gif", columnIndex, i, rootFolder);
                    string commonImg = string.Format("/{2}/images/leftbar_nav_{0}_{1}.gif", columnIndex, i, rootFolder);
                    string url = (string.IsNullOrEmpty(childColumn.Eclassname)) ? string.Format("/{0}/{1}", rootFolder, childColumn.Columnfilename) : string.Format("/{0}/{1}/{2}", rootFolder, childColumn.Eclassname, childColumn.Columnfilename);

                    if (("," + _dcm.Layerid + ",").IndexOf("," + childColumn.Classid + ",") > -1)
                    {
                        builder.AppendFormat("        <li><a href=\"{0}\"><img src=\"{1}\" alt=\"\" /></a></li>", url, selectedImg);
                    }
                    else
                    {
                        builder.Append("        <li><dl>");
                        builder.AppendFormat("            <dt><a href=\"{0}\"><img src=\"{1}\" alt=\"\" /></a></dt>", url, commonImg);
                        builder.AppendFormat("            <dd><a href=\"{0}\"><img src=\"{1}\" alt=\"\" /></a></dd>", url, arrowImg);
                        builder.Append("        </dl></li>");
                    }
                    i++;
                }
            }

            builder.Append("    </ul>");
            builder.Append("    <div class=\"clearfix\"><span>Clear Line</span></div>");
            builder.Append("</div>");
            return builder.ToString();
        }

        private Hashtable GetFirstLevelColumnHashtable(int rootColumnID)
        {
            int hcid = rootColumnID;
            IList clist = GetNavSonColumn(hcid);    // 取一级栏目
            Hashtable columnTable = new Hashtable();
            int startIndex = 2;
            foreach (ColumnModel column in clist)
            {
                columnTable.Add(column.Layerid, startIndex);
                startIndex++;
            }

            return columnTable;
        }

        private int FindColumnIndex(int rootColumnID, string layerID)
        {
            Hashtable columnTable = GetFirstLevelColumnHashtable(rootColumnID);
            int index = -1;
            IDictionaryEnumerator enumerator = columnTable.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (("," + layerID + ",").IndexOf("," + enumerator.Key + ",") > -1)
                {
                    index = (int)enumerator.Value;
                    break;
                }
            }

            return index;
        }

        private ColumnModel FindColumnByIndex(int rootColumnID, int index)
        {
            int hcid = rootColumnID;
            IList clist = GetNavSonColumn(hcid);    // 取一级栏目
            Hashtable columnTable = new Hashtable();
            int startIndex = 2;
            foreach (ColumnModel column in clist)
            {
                if (startIndex == index)
                    return column;
                startIndex++;
            }

            return null;
        }

        public string GetHeaderNavi(int rootColumnID)
        {
            int hcid = rootColumnID;
            ColumnModel _dcm = GetColumn(); //当前
            
            StringBuilder sb = new StringBuilder();
            if (_dcm.Classid == hcid)
                sb.Append("<script>var num=1;</script>\n");
            else
                sb.AppendFormat("<script>var num={0};</script>\n", FindColumnIndex(rootColumnID, _dcm.Layerid));

            return sb.ToString();
        }

        //public string GetEnLeftNavi()
        //{
        //    string[] colors = {"violet", "blue"};

        //    ColumnModel _dcm = GetColumn(); //当前
        //    int columnIndex = FindColumnIndex(_dcm.Layerid);
        //    string arrowImg = "/en/images/leftbar_nav_arrow_gray.gif";
        //    string color = colors[columnIndex - 2];
        //    string url = "/en/" + _dcm.HtmlFileName;

        //    StringBuilder builder = new StringBuilder();
        //    builder.AppendFormat("<div class=\"{0}\">", color);
        //    builder.Append("    <ul>");

        //    ColumnModel firstLevelColumn = FindColumnByIndex(columnIndex);
        //    if (firstLevelColumn == null) return null;

        //    IList childColumns = GetNavSonColumn(firstLevelColumn.Classid);
        //    int i = 1;
        //    foreach (ColumnModel childColumn in childColumns)
        //    {
        //        string selectedImg = string.Format("/en/images/leftbar_nav_{0}_{1}_now.gif", columnIndex, i);
        //        string commonImg = string.Format("/en/images/leftbar_nav_{0}_{1}.gif", columnIndex, i);
            
        //        if (("," + _dcm.Layerid + ",").IndexOf("," + childColumn.Classid + ",") > -1)
        //        {
        //            builder.AppendFormat("        <li><a href=\"{0}\"><img src=\"{1}\" alt=\"\" /></a></li>", "/en/" + childColumn.Columnfilename, selectedImg);
        //        }
        //        else
        //        {
        //            builder.Append("        <li><dl>");
        //            builder.AppendFormat("            <dt><a href=\"{0}\"><img src=\"{1}\" alt=\"\" /></a></dt>", "/en/" + childColumn.Columnfilename, commonImg);
        //            builder.AppendFormat("            <dd><a href=\"{0}\"><img src=\"{1}\" alt=\"\" /></a></dd>", "/en/" + childColumn.Columnfilename, arrowImg);
        //            builder.Append("        </dl></li>");
        //        }
        //        i++;
        //    }

        //    builder.Append("    </ul>");
        //    builder.Append("    <div class=\"clearfix\"><span>Clear Line</span></div>");
        //    builder.Append("</div>");
        //    return builder.ToString();
        //}

        private string GetContentNavi(ColumnModel cm, string str)
        {
            if (cm.Is_content_navi == 0) return "";
            StringBuilder sb = new StringBuilder();
            IList alist = CmsArticleFrontFactory.create().GetArticleOrderList(cm.Classid, 0);
            for (int i = 0; i < alist.Count; i++)
            {
                CmsArticleModel cam = (CmsArticleModel)alist[i];
                sb.Append(str.Replace("#current#", cam.Articletype == CmsConstants.ARTICLE_TYPE_DOWNLOAD ? i == alist.Count - 1 ? " class=\"mdown last\"" : " class=\"mdown last\"" : aid == cam.Articleid ? " class=\"current\"" : "").Replace("#name#", cam.Title).Replace("#url#", GetArticleUrl(cam)).Replace("#aclass#", cam.Articletype != CmsConstants.ARTICLE_TYPE_DOWNLOAD ? "class=\"menuIDD\"" : ""));

            }
            return sb.ToString();
        }

        //当前位置
        public string GetPositionNavi(int rootColumnID)
        {
            ColumnModel rootColumn = GetColumn(rootColumnID);
            string rootFolder = rootColumn.Eclassname;

            StringBuilder sb = new StringBuilder("<div id=\"crumbs\">");

            ColumnModel cm = GetColumn();
            string[] cs = cm.Layerid.Split(',');
            sb.Append("<span>").Append(rootFolder == "cn" ? "您的位置: " : "Your position: ").Append("</span>");

            string vpath = "";
            string url = string.Empty;
            for (int i = 1; i < cs.Length; i++)
            {
                int _cid = int.Parse(cs[i]);
                ColumnModel _cm = GetColumn(_cid);
                if (!string.IsNullOrEmpty(_cm.Eclassname))
                    vpath += "/" + _cm.Eclassname;

                url = (vpath.Length==0) ? _cm.Columnfilename : vpath + "/" + _cm.Columnfilename;
                if (i > 1)
                    sb.Append(" &gt; ");

                sb.AppendFormat("<a href=\"{0}\">{1}</a>", url, _cm.Classname);
            }

            sb.Append("</div>");
            return sb.ToString();
        }

        public string GetMenuListTitle()
        {
            string[] cs = GetColumn().Layerid.Split(',');
            StringBuilder sb = new StringBuilder();
            if (cs.Length > 2)
            {
                for (int i = cs.Length - 2; i > 0; i--)
                {
                    if (cs[i] == GetHomeId().ToString())
                    {
                        break;
                    }
                    sb.Append(" - ").Append(GetColumn(int.Parse(cs[i])).Classname);
                }
            }
            return sb.ToString();
        }
        /// <summary>
        /// 栏目KV图
        /// </summary>
        /// <returns></returns>
        public string GetColumntTitleImg()
        {
            string classpic = GetColumn().Classpic;
            if (classpic == null || classpic.Trim() == "")
            {
                string[] cs = GetColumn().Layerid.Split(',');
                if (cs.Length > 2)
                {
                    for (int i = cs.Length - 2; i > 0; i--)
                    {
                        classpic = GetColumn(int.Parse(cs[i])).Classpic;
                        if (classpic != null && classpic.Trim() != "")
                        {
                            break;
                        }
                        if (cs[i] == GetHomeId().ToString())
                        {
                            break;
                        }
                    }
                }
            }

            return ConConstants.UPLOADFILES_IMAGE_PATH + classpic;
        }

        /// <summary>
        /// 栏目SEO
        /// </summary>
        /// <returns></returns>
        public string GetColumntSEO(bool containsKeywords)
        {
            ColumnModel cm = GetColumn();
            string keyword = cm.Columnkeyword;
            string desc = cm.Columndesc;
            if (keyword == null || keyword.Trim() == "")
            {
                string[] cs = cm.Layerid.Split(',');
                if (cs.Length > 2)
                {
                    for (int i = cs.Length - 2; i > 0; i--)
                    {
                        ColumnModel temcm = GetColumn(int.Parse(cs[i]));
                        keyword = temcm.Columnkeyword;
                        desc = temcm.Columndesc;

                        if (keyword != null && keyword.Trim() != "")
                        {
                            break;
                        }
                        if (cs[i] == GetHomeId().ToString())
                        {
                            break;
                        }
                    }
                }
            }
            StringBuilder sb = new StringBuilder();
            if (containsKeywords)
            {
                sb.Append("<meta name=\"Keywords\" content=\"");
                sb.Append(keyword);
                sb.Append("\" />\n");
            }

            sb.Append("<meta name=\"Description\" content=\"");
            sb.Append(desc);
            sb.Append("\" />\n");
            sb.Append(CodeMeta());
            return sb.ToString();
        }
        /// <summary>
        /// 添加监测代码Meta
        /// </summary>
        /// <returns></returns>
        public string CodeMeta()
        {
            StringBuilder sb = new StringBuilder();
            ColumnModel cm = GetColumn();

            string c = GetColumnCodeMeta(cm);
            if (c != "") return c;

            string[] cs = cm.Layerid.Split(',');
            if (cs.Length > 0)
            {
                for (int i = cs.Length - 1; i > 0; i--)
                {
                    int _cid = int.Parse(cs[i]);
                    if (_cid >= GetHomeId())
                    {
                        ColumnModel _cm = GetColumn(_cid);
                        if (_cm.Code_meta != null && _cm.Code_meta != "")
                        {
                            return GetColumnCodeMeta(_cm);
                        }
                    }
                }
            }
            return "";
        }

        private string GetColumnCodeMeta(ColumnModel cm)
        {
            if (cm.Layerid.IndexOf("1,2,87,") > -1)
            {
                return "";
            }
            return cm != null && cm.Code_meta != null && cm.Code_meta != "" ? cm.Code_meta + "\n" : "";
        }
        /// <summary>
        /// 获取留言，回复信息
        /// </summary>
        /// <param> </param>
        /// <returns></returns>
        public string getContactusReply(int pagenum, int contacttype)
        {
           
            StringBuilder sb = new StringBuilder();
            
            return sb.ToString();
        }
        public string GetPageUrls(int pagenum, int contacttype)
        {
            if (contacttype == 1)
            {
                return "contact_us.aspx?pagenum=" + pagenum;
            }
            else
            {
                return "contact_us_business.aspx?pagenum=" + pagenum;
            }
        }
        /// <summary>
        /// 获取活动链接
        /// </summary>
        /// <param name="aid">活动id</param>
        /// <returns></returns>
        //public string getActivityLink(int aid)
        //{
        //    ActivityManageModel model = new ActivityManageModel();
        //    model = new ActivityManageBll().GetModel(aid);
        //    return getActivityLink(model);
        //}

        //public string getActivityLink(ActivityManageModel model)
        //{
        //    switch (model.Source)
        //    {
        //        case "1":
        //            return GetRootDir() + "/activity/activitydetails.aspx?aid=" + model.Activityid;
        //        case "2":
        //            return GetRootDir() + "/activity/activityphotos.aspx?aid=" + model.Activityid;
        //        case "3":
        //            if (!String.IsNullOrEmpty(model.Activitylink))
        //            {
        //                return model.Activitylink.IndexOf("http") > -1 ? model.Activitylink : "http://" + model.Activitylink;
        //            }
        //            else
        //                return GetRootDir() + "/activity/womai.aspx";
        //        default:
        //            return "";
        //    }
        //}

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="pagein">传进的页码</param>
        /// <param name="fact">参数链接</param>
        /// <param name="num">总页码</param>
        /// <returns></returns>
        //public string getIndexPage(int pagein, string fact, int num)
        //{
        //    StringBuilder sb = new StringBuilder();
        //    if (num > 0)
        //    {               
        //        sb.Append("<span class=\"prv\"><a " + (pagein <= 1 ? ("onclick=\"return false;\"") : "") + " href=\"" + (pagein > 1 ? fact + (pagein - 1) : "") + "\" >上一页</a></span>");
        //        if (num <= 5)
        //        {
        //            for (int i = 1; i <= num; i++)
        //            {

        //                sb.Append(pagein == i ? "<span class=\"f49\">" + i + "</span>" : "<a href=" + fact + i + ">" + i + "</a>");

        //            }
        //        }
        //        else
        //        {
        //            if (pagein <4)
        //            {
        //                for (int i = 1; i <= 5; i++)
        //                {

        //                    sb.Append(pagein == i ? "<span class=\"f49\">" + i + "</span>" : "<a href=" + fact + i + ">" + i + "</a>");

        //                }
        //                sb.Append("<a>...</a>");
        //            }
        //            else if (pagein >=4 && pagein < num-2)
        //            {
        //                sb.Append("<a>...</a>");
        //                for (int i = 1; i <= 5; i++)
        //                {
        //                    sb.Append(pagein == (pagein - 3 + i) ? "<span class=\"f49\">" + (pagein - 3 + i) + "</span>" : "<a href=" + fact + (pagein - 3 + i) + ">" + (pagein - 3 + i) + "</a>");
        //                }
        //                sb.Append("<a>...</a>");
        //            }
        //            else
        //            {
        //                sb.Append("<a>...</a>");
        //                for (int i = 1; i <= 5; i++)
        //                {
        //                    sb.Append(pagein == (num - 5 + i) ? "<span class=\"f49\">" + (num - 5 + i) + "</span>" : "<a href=" + fact + (num - 5 + i) + ">" + (num - 5 + i) + "</a>");
        //                }
        //            }
        //        }
        //        sb.Append("<span class=\"total\">共" + num + "页</span> <span class=\"next\">");
        //        sb.Append("<a " + (pagein >= num ? "onclick=\"return false;\"" : "") + "href=\"" + (pagein >= num ? fact + num : fact + (pagein + 1)) + "\">下一页</a></span>");
        //    }
        //    return sb.ToString();
        //}
        public int GetPageStartNo(int pagein, int num)
        {
            int inint = 1;
            if (num > 5 && pagein > 3)
            {
                if (pagein < num - 1)
                {
                    inint = pagein - 2;
                }
                else
                {
                    inint = num - 4;
                }
            }
            return inint;
        }
        public string getIndexPage(int pagein, string fact, int num)
        {
            StringBuilder sb = new StringBuilder();
            int inint = 1;
            if (num > 5&&pagein > 3)
            {
                if (pagein < num - 1)
                {
                    inint = pagein - 2;
                }
                else
                {
                    inint = num - 4;
                }
            }
            sb.Append("<span class=\"prv\"><a " + (pagein <= 1 ? ("onclick=\"return false;\"") : "") + " href=\"" + (pagein > 1 ? fact + (pagein - 1) : "") + "#ht\" >上一页</a></span>");
            for (int i = inint, p = 1; i <= num && p <= 5; i++, p++)
            {
                sb.Append(pagein == i ? "<span class=\"f49\">" + i + "</span>" : "<a href=" + fact + i + "#ht>" + i + "</a>");
            }
            sb.Append("<span class=\"total\">共" + num + "页</span> <span class=\"next\">");
            sb.Append("<a " + (pagein >= num ? "onclick=\"return false;\"" : "") + "href=\"" + (pagein >= num ? fact + num : fact + (pagein + 1)) + "#ht\">下一页</a></span>");
            return sb.ToString();
        }
        private static readonly string WAIMAI_LINK = ConfigurationSettings.AppSettings["womai.searchlink"];
        //我买购买搜索链接
        public string Getwaimai(string key)
        {
            return WAIMAI_LINK.Replace("#keyword#", HttpUtility.UrlEncode(key, System.Text.Encoding.GetEncoding("GB2312")));
        }

        //////-----------------栏目左主图加链接
        //关于我们
        public string GetAboutLeftImg()
        {
            return "<h2><a href=\""+ GetRootDir() + "/about/index.html\"><img src=\""+GetRootDir() + "/images/titleabout.gif\" border=\"0\"/></a></h2>";
        }
        //企业责任
        public string GetResponsibilityLeftImg()
        {
            return "<h2><a href=\""+GetRootDir() + "/responsibility/index.html\"><img src=\""+GetRootDir() + "/images/titleduty.gif\" border=\"0\"/></a></h2>";
        }
        //品牌
        public string GetBrandLeftImg()
        {
            return "<h2><a href=\""+GetRootDir() + "/brand/index.aspx\"><img src=\""+GetRootDir() + "/images/left_title_brand.gif\" border=\"0\"/></a></h2>";
        }
        //活动
        public string GetActivityLeftImg()
        {
            return "<h2><a href=\""+GetRootDir() + "/activity/index.aspx\"><img src=\""+GetRootDir() + "/images/titleHotGame.gif\" border=\"0\"/></a></h2>";
        }
        //美味人生
        public string GetHealthLeftImg()
        {
            return "<h2><a href=\""+GetRootDir() + "/health/index.html\"><img src=\""+GetRootDir() + "/images/titlecollege.gif\" border=\"0\"/></a></h2>";
        }
        //客户服务
        public string GetServiceLeftImg()
        {
            return "<h2><a href=\""+GetRootDir() + "/service/index.html\"><img src=\""+GetRootDir() + "/images/titleCustomerService.gif\" border=\"0\"/></a></h2>";
        }
    }
}
